<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <LINK type="text/css" rel="stylesheet" href="${ctx}/js/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/DetectionRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/UserRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
    <script type="text/javascript" src="${ctx}/js/layer/layer.js"></script>
</head>
<body>
<select id="detectionUserInfo" style="display: none;"></select>
<SCRIPT LANGUAGE="JavaScript" >
    var detectionThead = new Array(
        new XThead("首图"),
        new XThead("车辆信息"),
        new XThead("车商联系人信息"),
        new XThead("检测师信息"),
        new XThead("状态"),
        new XThead("操作")
    );

    var detectionXTable = new XTable("detection", detectionThead);

    var state_hash = {
            "0":"发起检测",
            "10":"已派单",
            "20":"已检测",
            "30":"检测完成"
        }

    detectionXTable.XTbodyArray = function (model) {
        var array = new Array(
		    new XTbody("detection", "<img src='${fdfsPath}" + model.car.carImageUrl + ".w_150xh_150'  />", "string", null, null, "center"),
		    new XTbody("detection", model.car.carTitle + "<br>车驾号：" + model.car.carVin + "<br>上牌日期：" + (model.car.carLicenceDate != null?model.car.carLicenceDate.Format("yyyy-MM-dd"):"未上牌") + "<br>车牌号：" + model.car.carPlate, "string", null, null, "center"),
		    new XTbody("detection", "公司名称：" + model.car.shop.shopName + "<br>联系方式：" + model.car.shop.shopMobile, "string", null, null, "center"),
		    new XTbody("detection", "检测师姓名：" + model.user.userName + "<br>检测师联系方式：" + model.user.userMobile, "string", null, null, "center"),
		    new XTbody("detection", state_hash[model.detectionState], "string", null, null, "center"),
		    new XTbody("detection", (model.detectionState == 0 ? "<a href='#'  style='border-right: 1px  class='contact-input'  onclick=selectDetectionUser('"+ model.marketId +"','" + model.detectionId +"','" + model.carId + "')>派单&nbsp;</a>":"") + "<a href='#'  style='border-right: 1px  class='contact-input'  onclick=\"javascript:location.href='${ctx}/controller/toDetectionDetail?detectionId=" + model.detectionId + "'\" />查看详情</a>", "string", null, null, "center")
		);
		return array;
    }

    detectionXTable.getXList = function (page){
        var detection = new Detection();
        detection.pageIndex = page;
        detection.pageSize = detectionXTable.pageSize;
        detection.marketId = '${marketId}';
        DetectionRpcService.selectDetectionList(detection, function(list){detectionXTable.addTable(list);});
    }
    function getDetectionPage() {
        var detection = new Detection();
        detection.marketId = '${marketId}';
        DetectionRpcService.selectDetectionNum(detection, function(num){detectionXTable.setTotalPage(num);}) ;
    }
    getDetectionPage();
    function selectDetectionUser(marketId, detectionId, carId){
        var user = new User();
        user.userType = 32;
        user.marketId = marketId;
        UserRpcService.selectUserList(user, callbackSelectUserList);
        layer.open({
            type:1,
            title:"选择检测师",
            content:$("#detectionUserInfo"),
            offset: '100px',
            btn:['确定','取消'],
            yes: function(index, layero){
                selectDetection(detectionId, $("#detectionUserInfo").val(), carId);
            },btn2: function(index, layero){
            }
          })
    }
    function callbackSelectUserList(list) {
        dwr.util.removeAllOptions("detectionUserInfo");
        dwr.util.addOptions("detectionUserInfo", list, "userId", "userName");
    }
    function selectDetection(detectionId, userId, carId){
        var detection = new Detection();
        detection.detectionId = detectionId;
        detection.detectUserId = userId;
        detection.carId = carId;
        detection.detectionState = 10;
        DetectionRpcService.updateDetection(detection, function(res){if(res == 1){alert("派单成功");location.reload();}});
    }
</SCRIPT>
</body>
</html>
